<!-- 传统报单 -->
<template>
  <div class="container">
    <div class="content">
      <div class="item mb_0">
        <div>
          报单日期&nbsp;：
          <input type="text" v-model="form.create_time" placeholder="请选择日期" />
        </div>
        <div class="list-buttom cur-date" @click="showDatePicker">
          <span class="icon-span">
            <Icon type="ios-arrow-right" class="select-icon"></Icon>
          </span>
        </div>
      </div>
      <div class="item pd_0">
        <div>
          医&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;院：
          <div class="select_box">
            <cube-select
              v-model="form.hospital_id"
              :options="hospitalList"
              title="医院"
              placeholder="请选择医院"
            ></cube-select>
            <Icon type="ios-arrow-right" class="select-icon"></Icon>
          </div>
        </div>
      </div>
      <div class="item">
        <div>
          项目名称&nbsp;：
          <input type="text" v-model="form.dd_project_name" placeholder="请选择医院" />
        </div>
      </div>
      <div class="item">
        <div>
          用&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;户：
          <input
            type="text"
            v-model="form.user"
            placeholder="请输入姓名/手机号"
          />
        </div>
      </div>
      <div class="item">
        <div>
          推&nbsp;&nbsp;荐&nbsp;&nbsp;人：
          <input
            type="text"
            v-model="form.refer"
            placeholder="请输入推荐人姓名"
          />
        </div>
      </div>
      <div class="item">
        <div>
          报&nbsp;&nbsp;单&nbsp;&nbsp;人：
          <input
            type="text"
            v-model="form.declare_user"
            placeholder="请输入姓名"
          />
        </div>
      </div>
      <div class="search" @click="toSearch(1)">查询</div>
      <div class="createForm" @click="toSearch(2)">创建报单</div>
    </div>
  </div>
</template>

<script>
import api from "../../assets/js/api";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      hospitalList: [],
      form: {
        user: "",
        refer: "",
        create_time: "",
        hospital_id: "",
        dd_project_name: "",
        declare_user: "",
        limit: 50
      }
    };
  },

  components: {},

  mounted() {
    this.axios.defaults.baseURL = api;
    this.initDate();
    this.selectHospital();
  },

  methods: {
    selectHospital() {
      this.axios.post("api/butler/declaration/hospital").then(res => {
        if (res.data.code == 200) {
          let arr = res.data.data;
          if (arr.length > 0) {
            res.data.data.forEach(item => {
              item.text = item.hospital_name;
              item.value = item.id;
            });
          }
          this.hospitalList = arr;
        }
      });
    },
    // 查询接口
    handleSearch() {},
    // 查询
    toSearch(type) {
      if (type == 1) {
        if (!this.form) {
          console.log('请填写');
          return false;
        }
              this.$router.push({path:"/searchResult",query:{...this.form}});
   
      } else if (type == 2) {
        this.$router.push({path:"/createForm",query:{pageType:'add'}});
      }
    },
    showDatePicker() {
      if (!this.datePicker) {
        this.datePicker = this.$createDatePicker({
          title: "日期",
          min: new Date(this.minDate),
          max: new Date(this.maxDate),
          value: new Date(),
          onSelect: (date, selectedVal, selectedText) => {
            console.log(selectedVal);
            let tostring =
              selectedVal[0] + "-" + selectedVal[1] + "-" + selectedVal[2];

            //解决ios手机上面 时间格式化问题
            tostring = tostring.replace(/\-/g, "/");
            //日期格式化
            tostring = new Date(tostring).Format("yyyy-MM-dd");
            // this.today = tostring;
            this.form.create_time = tostring;
            console.log("form", this.form.create_time);
            //向父组件传递值
            // this.$emit('selectDate', this.today);
          },
          onCancel: () => {
            console.log("取消了");
          }
        });
      }
      this.datePicker.show();
    },
    // 初始化时间
    initDate() {
      // let today = new Date().Format("yyyy-MM-dd");
      // this.today = today;
      // this.form.create_time = today;

      //时间筛选器 最小值 和 最大值
      // let select_date = sessionStorage.getItem("select_date");
      // select_date = JSON.parse(select_date)

      let curDate = new Date().getDate();
      //截止时间
      let date1 = new Date();
      date1 = new Date(date1.setDate(curDate + 2)).Format("yyyy-MM-dd");
      //开始时间
      let date2 = new Date();
      date2 = new Date(date2.setDate(curDate - 30)).Format("yyyy-MM-dd");

      console.log(date2, date1);
      this.minDate = date2;
      this.maxDate = date1;
      console.log("initDate");
    }
  }
};
</script>
<style  scoped>
.container {
  width: 100%;
  background: #fff;
}
.content {
  padding: 15px 15px 13px 15px;
  font-size: 17px;
  color: #666;
  font-family: "font-family: PingFangSC-Medium, PingFang SC";
  font-weight: 500;
  box-sizing: border-box;
}
.item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #ccc;
  box-sizing: border-box;
}
.select_box {
  padding-bottom: 10px;
  display: inline-block;
}
.cube-select {
  padding: 0;
  width: 250px;
}
.cube-select /deep/ .cube-select-placeholder {
  font-size: 17px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #c5c5c5;
  line-height: 24px;
}
.cube-select /deep/ .cube-select-text {
  font-size: 17px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #000;
}
.mb_0 {
  margin-bottom: 3px !important;
}
.pd_0 {
  padding-bottom: 3px !important;
}
input::-webkit-input-placeholder {
  color: #c5c5c5;
  font-weight: 400;
}
.cube-select-icon {
  border: none !important;
}
.select-icon {
  display: block;
  font-size: 20px;
  position: absolute !important;
  right: 0px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  z-index: 99;
}
.cube-select::after {
  border: 0 !important;
}
.search {
  width: 146px;
  height: 31px;
  line-height: 31px;
  text-align: center;
  background: #ffffff;
  border-radius: 24px;
  color: #ffa4ba;
  font-size: 14px;
  border: 1px solid #ffa7bc;
  margin: 55px auto;
  box-sizing: border-box;
}
.createForm {
  width: 226px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 14px;
  color: #fff;
  background: linear-gradient(180deg, #ffdddd 0%, #ff83a6 100%);
  border-radius: 24px;
  margin: 70px auto;
  box-sizing: border-box;
}
</style>